package com.cictec.middleware.gps.caculate.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cictec.middleware.gps.caculate.BusMileageManager;
import com.cictec.middleware.gps.caculate.BusTripEngine;
import com.cictec.middleware.gps.caculate.service.BusMileageService;
import com.cictec.middleware.gps.engine.TimingPoint;
import com.cictec.middleware.gps.engine.caculate.entity.BusMileage;
import com.cictec.middleware.gps.engine.caculate.entity.BusTrip;

@Controller
public class GpsCaculateController {

	@Autowired
	private BusTripEngine busTripEngine;
	@Autowired
	private BusMileageService busMileageService;
	@Autowired
	private BusMileageManager busMileageManager;

	/**
	 * 根据时序点计算里程信息，按照里程状态区分
	 * 
	 * @param position
	 * @return
	 */
	@RequestMapping(value = "/gps/caculate")
	public void caculateMileage(@RequestParam("date") String date, @RequestParam("devCode") String devCode) {
		date = "2017-05-03";
		devCode = "21590";
		List<String> devCodeList = new ArrayList<String>();
		devCodeList.add(devCode);
		busMileageManager.caculateByDevCode(date, devCodeList);
	}

	/**
	 * 根据时序点计算里程信息，按照里程状态区分
	 * 
	 * @param position
	 * @return
	 */
	@RequestMapping(value = "/gps/caculate/caculateMileage")
	public List<BusMileage> caculateMileage(List<TimingPoint> timingPoints) {
		return busMileageService.caculateMileage(timingPoints);
	}

	/**
	 * 获取上一个完成的趟次信息
	 * 
	 * @param devCode
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value = "/gps/caculate/getLastBusTrip")
	public BusTrip getLastBusTrip(@RequestParam("devCode") String devCode, @RequestParam("endTime") Date endTime) {
		return busTripEngine.getLastBusTrip(devCode, endTime);
	}
}
